﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_DangNhap : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["DangNhap"] == null)
        {
            PannelChuaDN.Visible = true;
            PanelDaDN.Visible = false;
            lbLoi.Visible = false;
        }
        else
        {
            PanelDaDN.Visible = true;
            PannelChuaDN.Visible = false;
            Chao.Text = Session["DangNhap"].ToString();
            lbTaiKhoan.Text = Session["tkCon"].ToString()+"VND";
        }

    }
    protected void btnDangNhap_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        XuLy xl = new XuLy();
        string  query = "select * from KhachHang where TenDN='"+txtTenDN.Text+"' and MatKhau='"+txtMatKhau.Text+"'";
        dt = xl.Load(query);
        if (dt.Rows.Count >0)
        {
            Session["DangNhap"] = dt.Rows[0]["TenDN"].ToString();
            Chao.Visible = true;
            
            DataTable taikhoan = xl.Load("select taikhoan from khachhang where tendn='" + Session["DangNhap"].ToString() + "'");
            Session["tkCon"] = Convert.ToString(taikhoan.Rows[0][0].ToString());
            lbTaiKhoan.Visible = true;
            PannelChuaDN.Visible = false;
            PanelDaDN.Visible = true;
            DataTable tb = new DataTable();
            if (Session["GioHang"] != null)
            {
                tb = (DataTable)Session["GioHang"];
            }
            else
            {
                Session["GioHang"] = null;
            }
           
              
        }
        else
        {
            lbLoi.Visible = true;
            lbLoi.Text = "Đăng Nhập Sai! ";
           
        }
        Response.Redirect("~/TrangChu.aspx");
    }


    protected void btnThoat_Click1(object sender, EventArgs e)
    {
        Session["GioHang"] = null;
        Session["DangNhap"] = null;
        PannelChuaDN.Visible = true;
        PanelDaDN.Visible = false;
        lbLoi.Visible = false;
        Response.Redirect("~/TrangChu.aspx");
       
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/TrangChu.aspx?doimk=DoiMatKhau");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/TrangChu.aspx?ThongTinKH=ThongTinKhachHang");
    }
}